struct VertexBufferOutput
{
	float2 f2Tex									: TEXCOORD0;
	float4 f4NormalWorld							: NORMAL;
	float4 f4ViewDirectionWorld						: TEXCOORD1;
	float4 f4LightDirectionWorld					: TEXCOORD2;
	//float4 f4PositionClip							: SV_POSITION;
};

Texture2D<float4> g_Texture : register(t0);
SamplerState g_LinearSampler : register (s0);

cbuffer Static										: register (cb0)
{
	static const float4 g_f4LightPositionWorld = float4( 200, 10, 200, 0.0f );
	static const float4 g_f4LightColor = float4( 1.0f, 1.0f, 1.0f, 1.0f);

	static const float4 g_f4AmbientColor = float4(0.9f, 0.9f, 0.9f, 1.0f);
	static const float4 g_f4DiffuseColor = float4(0.5f, 0.5f, 0.5f, 1.0f);
	static const float4 g_f4LightDirection = float4(-1.0f, -1.0f, -1.0f, 1.0f);
	static const float4 g_fSpecularColor = float4(0.3f, 0.3f, 0.3f, 1.0f);
	static const float g_fSpecularPower = 5.0f;

};

float4 main( VertexBufferOutput In )				: SV_TARGET
{
	//printf( "Pixel shader call" );

	float4 f4Color = g_f4AmbientColor;
	float4 f4TexColor = g_Texture.Sample(g_LinearSampler, In.f2Tex);
	float4 f4Specular = float4(0.0f, 0.0f, 0.0f, 0.0f);
	float4 f4LightDirection = -In.f4LightDirectionWorld;

	float fLightIntensity = saturate(dot(In.f4NormalWorld.xyz, f4LightDirection.xyz));
	if ( fLightIntensity > 0.0f)
	{
		f4Color += g_f4DiffuseColor * fLightIntensity;
		f4Color = saturate(f4Color);

		float3 f3Reflection = normalize(In.f4NormalWorld.xyz * 2 * fLightIntensity - f4LightDirection.xyz);
		f4Specular = pow(saturate(dot(f3Reflection, In.f4ViewDirectionWorld.xyz)), g_fSpecularPower);
	}
	else
	{
		f4Color = saturate(f4Color);
	}

	f4Color *= f4TexColor;
	f4Color += f4Specular;
	f4Color = saturate(f4Color);

	return f4Color;
}